<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div,span,a{
            display: block;
            min-height: 40px;
        }
    </style>
</head>

<body>
    <div id="a">1</div>
    <div class="b">2</div>
    <span class="b">3</span>
    <span id="b">4</span>
    <a href="#" class="a">5</a>
    <button onclick="bian()">变</button>
    <script>
        function $(s){
            return document.querySelector(s);
        }
        function $$(s){
            return document.querySelectorAll(s);
        }
        function bian() {
            // 数组
            var a = document.querySelectorAll('.a');
            // 数组需要循环
            for (var i = 0; i < a.length; i++) {
                var element = a[i];
                element.style.background = '#f00';
            }
            
            var b = $$('.b');
            for (var i = 0; i < b.length; i++) {
                var element = b[i];
                element.style.background = '#00f';
            }
        }
    </script>
</body>

</html>